﻿package racingGame.utils 
{
	import away3d.core.math.Number3D;
	/**
	 * ...
	 * @author ...
	 */
	public class MathUtils
	{
		
		public function MathUtils() 
		{
			
		}
		
		public static function getLineLineIntersection (v1:Number3D, v2:Number3D, v3:Number3D, v4:Number3D) :Number3D
		{
			
			var intersection :Number3D = new Number3D();
			
			
			intersection.x = ((v1.x * v2.z - v1.z * v2.x) * (v3.x - v4.x) - (v1.x - v2.x) * (v3.x * v4.z - v3.z * v4.x)) / ((v1.x - v2.x) * (v3.z - v4.z) - (v1.z - v2.z) * (v3.x - v4.x));
			intersection.z = ((v1.x * v2.z - v1.z * v2.x) * (v3.z - v4.z) - (v1.z - v2.z) * (v3.x * v4.z - v3.z * v4.x)) / ((v1.x - v2.x) * (v3.z - v4.z) - (v1.z - v2.z) * (v3.x - v4.x));
			
			return intersection;
		}
		
	}

}